// pages/userCommit/userCommit.js
import {userCommitBehavior} from './behavior'
import dayjs from 'dayjs'
import {queryComment} from '../../api/comment'
Page({
  behaviors: [userCommitBehavior],

  /**
   * 页面的初始数据
   */
  data: {
    commentList: []
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getCommentList()
  },

  async getCommentList() {
    // 获取店铺评论
    const {data} = await queryComment({userid: this.data.userInfo.id})
    data.forEach(item => {
      item.rate = item.rate && JSON.parse(item.rate)
      item.createTime = dayjs(item.createTime).format("YYYY-MM-DD")
    })
    this.setData({
      commentList: data
    })
  },
})